//
//  OASubmitTests.m
//  OANetworkManager_Tests
//
//  Created by TFAppleWork-Summer on 2018/3/2.
//  Copyright © 2018年 GuoRui. All rights reserved.
//

#import "Tests.h"
#import "AppNetworkingManager+OASubmit.h"
#import "OADailyReportDetailModel.h"
#import "OAOvertimeReportCommitModel.h"
#import "OAUserModel.h"
#import "OALeaveReportCommitModel.h"


@interface OASubmitTests : Tests

@end

@implementation OASubmitTests

- (void)setUp {
    [super setUp];
    // Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown {
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    [super tearDown];
}

- (void)testExample {
    // This is an example of a functional test case.
    // Use XCTAssert and related functions to verify your tests produce the correct results.
}

-(void)testJournalAddOrUpdate{
    
    [self expectation:^(void (^fulfill)(void)) {
        
        NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
        [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        NSString *dateStr = @"2018-03-01 18:00:00";
        NSDate *date = [formatter dateFromString:dateStr];
        long long dateTime  = [date timeIntervalSince1970] * 1000;
        
        OADailyReportDetailModel *model = [[OADailyReportDetailModel alloc]init];
        model.finishWorks=@"工作起来就像陀螺一样";
        model.time= dateTime;;
        model.reportType=101;
        //创建一个抄送人
        OAUserModel *useModel = [[OAUserModel alloc]init];
        useModel.userId = @"163";
        useModel.userName = @"郭睿";
        model.ccs = @[useModel];
        model.coordinateWorks = @"需要协调的工作";
        model.unfinishWorks = @"未完成的工作";

        
        [AppNetworkingManager addOrUpdateJournalWithModel:model complete:^(id object, NSError *error) {
            fulfill();
        }];
        
    }];
}

-(void)testOverTimeAddOrUpdate{
    
    [self expectation:^(void (^fulfill)(void)) {
        
        NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
        [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        NSString *dateStr = @"2018-02-01 18:30:00";
        NSDate *date = [formatter dateFromString:dateStr];
        long long startTime  = [date timeIntervalSince1970] * 1000;
       
        NSString *dateStr1 = @"2018-02-01 21:30:00";
        NSDate *date1 = [formatter dateFromString:dateStr1];
        long long endTime  = [date1 timeIntervalSince1970] * 1000;
        OAOvertimeReportCommitModel *overTimeCommitModel = [[OAOvertimeReportCommitModel alloc]init];
        overTimeCommitModel.reportType = ReportTypeOvertime;
        overTimeCommitModel.startTime = startTime;
        overTimeCommitModel.endTime = endTime;
        overTimeCommitModel.project = @"无限产品中心";
        overTimeCommitModel.workContent = @"工作内容";
        // 创建一个抄送人
        OAUserModel *useModel = [[OAUserModel alloc]init];
        useModel.userId = @"163";
        useModel.userName = @"郭睿";
        overTimeCommitModel.ccs = @[useModel];
        
        [AppNetworkingManager addOrUpdateOverTimeWithModel:overTimeCommitModel complete:^(id object, NSError *error) {
            fulfill();
        }];
        
    }];
    
}

-(void)testGetLeaveType{
    
    [self expectation:^(void (^fulfill)(void)) {
        [AppNetworkingManager getLeaveTypeComplete:^(id object, NSError *error) {
            NSLog(@"请假类型%@",object);
            fulfill();
        }];
    }];
}

-(void)testAddOrUpdateLeaveReport{
    
    [self expectation:^(void (^fulfill)(void)) {
        OALeaveReportCommitModel *leaveCommitModel= [[OALeaveReportCommitModel alloc]init];
        
        leaveCommitModel.reportType = ReportTypeLeave;
        leaveCommitModel.duration = @"一天";
        leaveCommitModel.leaveType = 6;
        leaveCommitModel.reason = @"我最近比较烦，比较烦，比较烦";
        NSArray *timeRanges = @[[NSString stringWithFormat:@"%lld,%lld",[self getTimeDateWithString:@"2018-03-01 12:00:00"],[self getTimeDateWithString:@"2018-03-01 18:00:00"]]];
        leaveCommitModel.timeRanges = [timeRanges yy_modelToJSONString];
        OAUserModel *useModel = [[OAUserModel alloc]init];
        useModel.userId = @"163";
        useModel.userName = @"郭睿";
        leaveCommitModel.ccs = @[useModel];
        [AppNetworkingManager addOrUpdateLeaveWithModel:leaveCommitModel Complete:^(id object, NSError *error) {
            if (error) {
                NSLog(@"请假失败：%@",error.localizedDescription);
            }
            else{
                NSLog(@"请假成功%@",object);
            }
            fulfill();
        }];
    }];
}

- (void)testPerformanceExample {
    // This is an example of a performance test case.
    [self measureBlock:^{
        // Put the code you want to measure the time of here.
    }];
}

@end
